<template>
  <view class="static-list">
    <OrderStaticList order-type="measure" :data-list="dataList" :data-obj="dataObj" :submit-show="btnShow" :submit-text="submitText" :work-id="workId" @submit="submit" @add-remark-success="addRemarkSuccess" />
  </view>
</template>

<script>
  import OrderStaticList from '../../../../components/order-static-list/OrderStaticList';
  import { getMeasureOrderStatus } from '../../../../api/device/device';
  
  export default {
    name: 'staticList',
    components: {
      OrderStaticList,
    },
    data() {
      return {
        workId: '',
        dataList: [],
        dataObj: {},
        initFinish: false,
      };
    },
    computed: {
      btnShow() {
        const userState = this.$store.state.user.userState * 1;
        const workStatus = this.dataObj.workStatus * 1;
        let isShow = workStatus < 3;
        isShow = isShow && ((userState === 2 && workStatus === 2) || (userState === 1 && workStatus === 1));
        return isShow;
        // this.$store.state.user.userState * 1 === 2
      },
      submitText() {
        const workStatus = this.dataObj.workStatus * 1;
        return workStatus > 1 ? '工单验收' : undefined;
      },
    },
    methods: {
      async getData() {
        const res = await getMeasureOrderStatus({ workId: this.workId });
        if (res.code === 200 && res.data) {
          this.dataObj = res.data;
          this.dataList = res.data.list || [];
        }
      },
      submit() {
        uni.navigateTo({
          url: `/pages/order/order-detail/measure/orderDetail?workId=${this.workId}&status=${this.dataObj.workStatus}`,
        });
      },
      addRemarkSuccess() {
        this.getData();
      },
    },
    onShow() {
      const pageList = getCurrentPages();
      const param = pageList[ pageList.length - 1 ].options || {};
      this.workId = param.workId;
      this.getData();
    },
  };
</script>

<style lang="scss" scoped>
  .static-list {
    &, * {
      box-sizing: border-box;
    }
    height: 100%;
  }
  
  page {
    background-color: white;
  }
  
  uni-page-body {
    height: 100%;
  }
</style>
